import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/pages/index',
      meta: {
        title: '首页'
      },
      component: function (resolve) {
        require(['@/pages/index'], resolve)
      }
    }
  ],
  mode: 'history', // 路由模式
  strict: process.env.NODE_ENV !== 'production',
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: to.meta.savedPosition || 0
      }
    }
  }
})

router.beforeEach((to, from, next) => {
  console.log(to, from)
  const isLogin = !!wx.getStorageSync('token')
  isLogin ? next() : next('/pages/index')
  // next()
})

// router.afterEach((toRoute, fromRoute) => {

// })

export default router
